package com.tnl.utils;

import java.io.IOException;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;


/*
功能:		企信通PHP HTTP接口 发送短信
修改日期:	2014-03-19
说明:		http://api.cnsms.cn/?ac=send&uid=用户账号&pwd=MD5位32密码&mobile=号码&content=内容
状态:
	100 发送成功
	101 验证失败
	102 短信不足
	103 操作失败
	104 非法字符
	105 内容过多
	106 号码过多
	107 频率过快
	108 号码内容空
	109 账号冻结
	110 禁止频繁单条发送
	111 系统暂定发送
	112 号码不正确
	120 系统升级
*/
public class SMSUtils {
	//sms zhidao
	public static final String smsZDUid="medtalentZD";
	public static final String smsZDKey="0b30ebfb2cd76b1aa193";
	
	public static String sendSmsOrderToUser(String phoneNum, String content) throws Exception {
		HttpClient client = new HttpClient();
		PostMethod post = new PostMethod("http://sms.webchinese.cn/web_api/");
		post.addRequestHeader("Content-Type",
				"application/x-www-form-urlencoded;charset=gbk");

		NameValuePair[] data = {
				new NameValuePair("Uid",smsZDUid),
				new NameValuePair("Key",smsZDKey),
				new NameValuePair("smsMob", phoneNum),
				new NameValuePair("smsText", content)
		
		};

		post.setRequestBody(data);

		client.executeMethod(post);
		Header[] headers = post.getResponseHeaders();
		int statusCode = post.getStatusCode();
		System.out.println("statusCode:" + statusCode);
		for (Header h : headers) {
			System.out.println(h.toString());
		}
		String result = new String(post.getResponseBodyAsString().getBytes(
				"gbk"));

		System.out.println("result" + result);
		post.releaseConnection();
		return result;
	}
	
	public static String sendSmsOrderToHunter(String phoneNum, String name,String content) throws Exception {
		HttpClient client = new HttpClient();
		PostMethod post = new PostMethod("http://sms.webchinese.cn/web_api/");
		post.addRequestHeader("Content-Type",
				"application/x-www-form-urlencoded;charset=gbk");

		NameValuePair[] data = {
				new NameValuePair("Uid",smsZDUid),
				new NameValuePair("Key",smsZDKey),
				new NameValuePair("smsMob", phoneNum),
				new NameValuePair("smsText", content)
		
		};

		post.setRequestBody(data);

		client.executeMethod(post);
		Header[] headers = post.getResponseHeaders();
		int statusCode = post.getStatusCode();
		System.out.println("statusCode:" + statusCode);
		for (Header h : headers) {
			System.out.println(h.toString());
		}
		String result = new String(post.getResponseBodyAsString().getBytes(
				"gbk"));

		System.out.println("result" + result);
		post.releaseConnection();
		return result;
	}
	
	
	public static void main(String[] args) {
		try {
			//sendSMSOpinion("13611884993", "Lin", "");
//			sendLogin("13611884993", "15921855291@163.com");
			System.out.println("xxxxxxx");
//			sendSmsOrderToUser("13584593495");
//			sendSMSrefuseOrder();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}